package com.xckj.cycling.presenter;

import androidx.annotation.NonNull;

import com.xckj.cycling.bean.BaseBean;
import com.xckj.cycling.framework.net.RetrofitManager;
import com.xckj.cycling.global.Constant;
import com.xckj.cycling.iview.IReportDeviceDataView;

import java.util.Objects;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @Author: ChenYao
 * @Describe: 蓝牙更新设备数据
 * @Date: 2023/3/18 16:15
 */
public class ReportDeviceDataPresenter {
//    private final IReportDeviceDataView reportDeviceDataView;
//
//    public ReportDeviceDataPresenter(IReportDeviceDataView reportDeviceDataView) {
//        this.reportDeviceDataView = reportDeviceDataView;
//    }

    public ReportDeviceDataPresenter() {
    }

    public void reportDeviceData(String model,String curr_dangwei, String curr_sudu,String avg_sudu,String zuida_sudui,
                                 String electricity, String totalmileage, String canmileage, String danci, String mac) {
//        reportDeviceDataView.showLoading();
        Call<BaseBean<String>> call = RetrofitManager.getInstance().getService().
                reportDeviceData(model,curr_dangwei, curr_sudu,avg_sudu,zuida_sudui,
                        electricity, totalmileage, canmileage, danci, mac);
        call.enqueue(new Callback<BaseBean<String>>() {
            @Override
            public void onResponse(@NonNull Call<BaseBean<String>> call, @NonNull Response<BaseBean<String>> response) {
                if (response.isSuccessful()) {
                    BaseBean<String> baseBean = response.body();
                    if (Constant.SUCCESS_CODE == Objects.requireNonNull(baseBean).code) {
//                        reportDeviceDataView.report_success();
                    } else {
//                        reportDeviceDataView.report_failure(baseBean.msg);
                    }
                } else {
//                    reportDeviceDataView.report_failure("request failed");
                }
//                reportDeviceDataView.hideDialog();
            }

            @Override
            public void onFailure(@NonNull Call<BaseBean<String>> call, @NonNull Throwable t) {
                t.printStackTrace();
//                reportDeviceDataView.report_failure("request failed");
//                reportDeviceDataView.hideDialog();
            }
        });
    }
}
